
@page "/ticketlistdetail/{TicketID}"
@attribute [UserNavigation("工单详情")]
@attribute [Authorize]
@rendermode InteractiveServer
<AuthorizeView>
    <Authorized>
        @if (_workOrder != null){
           <Collapse>
                <CollapseItems>
                    <CollapseItem Text="工单详情" >
                    <Ticket TicketID="@TicketID"   @ref="TicketComponent"></Ticket>
                    </CollapseItem>
                    <CollapseItem Text="工单时间轴" IsCollapsed="false">
                    <Timeline Items="TimelineItems" IsAlternate="true" />
                    </CollapseItem>
                </CollapseItems>
            </Collapse>

        }
        else{
            <h3 class="text-danger">工单不存在</h3>
        }
   
 
    </Authorized>
</AuthorizeView>



@code{

[Parameter]
[Required] 
public required string TicketID { get; set; }
private Ticket? TicketComponent;
[Inject]
private  IWorkOrderService WorkOrderService { get; set; }
[Inject]
private  MyIdentityContext AppContext   { get; set; }
private 工单主表 _workOrder = new 工单主表();

private List<模板字段表> _templateFields = new();

private List<工单分派记录表> Handlers= new List<工单分派记录表>();


private List<TimelineItem> TimelineItems = new List<TimelineItem>();

protected override async Task OnInitializedAsync()
{  
 
  _workOrder = await WorkOrderService.GetWorkOrderByIdAsync(TicketID);


    TimelineItems = await GetCustomerComponentTimelineItems(TicketID); 
        
 
        

}     

 private async Task<List<TimelineItem>> GetCustomerComponentTimelineItems(string TicketID)
 {




var items = (await WorkOrderService.GetWorkOrderslog(TicketID)).Select(log => new TimelineItem
{
    Content = log.操作详情,
    Color = log.操作类型 switch
    {
        OperationType.创建 => Color.Primary,
        OperationType.更新 => Color.Info,
        OperationType.解决 => Color.Success,
        OperationType.关闭 => Color.Success,
        OperationType.添加附件 => Color.Danger,
        OperationType.重新打开 => Color.Warning,
        OperationType.分派 => Color.Info,
        OperationType.拆分 => Color.Secondary,
        OperationType.转移 => Color.Secondary,
        OperationType.评论 => Color.Light,
        _ => Color.Dark
    }, 
     Description = $"操作人: {log.操作人id} 操作时间: {log.操作时间:yyyy-MM-dd HH:mm:ss}"
}).ToList();

return  items;
    
}
}